<template>
    <view>
        <u-modal
            v-model="showModel"
            @confirm="confirm"
            @cancel="cancel"
            :show-cancel-button="options.showCancel"
            :title="options.title"
            :confirm-text="options.confirmText || '确认'"
            :cancel-text="options.cancelText || '取消'"
            :show-title="options.title != null && options.title !== ''"
            :title-style="{ 'font-size': '40rpx' }"
            style="z-index: 9999"
        >
            <view class="modelContent">
                <view>
                    {{ options.content }}
                </view>
            </view>
        </u-modal>
    </view>
</template>

<script lang="ts" setup>
import { onUnmounted, reactive, ref } from 'vue'
import { useGlobalStore } from '@/store'
import { onLoad } from '@dcloudio/uni-app'

const globalStore = useGlobalStore()

let options = reactive<any>({
    title: '',
    content: '',
    showCancel: true
})

let result = reactive({
    confirm: false,
    cancel: false
})

const showModel = ref(true)

onLoad((option: any) => {
    if (option.showCancel == 'false') option.showCancel = false
    options = Object.assign(options, option)
})

onUnmounted(() => {
    globalStore.canIpop = true
})

function closeModal() {
    uni.$emit('CModelCallback', result)
    if (options.noBack) return // 如果有这个参数  则不执行 uni.navigateBack
    uni.navigateBack({
        delta: 1
    })
    console.log('返回上一页')
}

function cancel() {
    result.cancel = true
    closeModal()
}
function confirm() {
    result.confirm = true
    closeModal()
}
</script>

<style lang="scss" scoped>
page {
    background: transparent;
}
.modelContent {
    padding: 38rpx;
    text-align: center;
    .icon {
        margin-right: 30rpx;
    }
}
</style>
